    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PM;

/**
 *
 * @author s4201567 Tony Yu
 */
import csse3004.GD.DA.PollMasterDA;
import csse3004.GD.Participant;
import csse3004.GD.ParticipantListTemplate;
import java.util.ArrayList;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author Tony Yu s4201567
 */
public class ViewParticipantListController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    private PollMasterService pms = new PollMasterDA();

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
        ArrayList<ParticipantListTemplate> temps = new ArrayList<ParticipantListTemplate>();
        ArrayList<String> demos = new ArrayList<String>();
        ArrayList<Participant> parts = new ArrayList<Participant>();
        
        try{ 
            int tempID = Integer.parseInt(hsr.getParameter("tempID"));

            logger.info("tempID: " + tempID);
            temps = pms.getTemplates();
            demos = pms.getTemplateDemographics(tempID);
            parts = pms.getParticipants(tempID);

            ModelAndView mnv = new ModelAndView("viewList", "temps", temps);
            mnv.addObject("demos", demos);
            mnv.addObject("parts", parts);

            return mnv;
        }
        catch (Exception e){
            logger.info(e);
            return new ModelAndView("viewList");
        }
    }
}
